c++
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int N=10005;
std::vector<int>g[N];
int dfn[N],low[N],timer;
int scc[N],sccCnt;
std::vector<int>stk;
bool in_stk[N];
int n;
int out[N],in[N];
void tarjan(int u){
dfn[u]=low[u]=++timer;
stk.push_back(u);
in_stk[u]=true;
for(int v:g[u]){
if(!dfn[v]){
tarjan(v);
low[u]=std::min(low[u],low[v]);
}else if(in_stk[v]){
low[u]=std::min(low[u],dfn[v]);
}
}
if(dfn[u]==low[u]){
++sccCnt;
int v;
do{
v=stk.back();
stk.pop_back();
scc[v]=sccCnt;
in_stk[v]=false;
}while(v!=u);
}
}
void fc() {
std::cin>>n;
std::vector<std::pair<int,int>>e;
for(int i=1;i<=n;i++){
int x;std::cin>>x;
while(x){
g[i].push_back(x);
e.push_back({i,x});
std::cin>>x;
}
}
for(int i=1;i<=n;i++)if(!dfn[i])tarjan(i);
int ocnt=sccCnt,icnt=sccCnt;
for(auto& [x,y]:e){
int u=scc[x],v=scc[y];
if(v==u)continue;
if(out[u]++==0)ocnt--;
if(in[v]++==0)icnt--;
}
std::cout<<icnt<<"\n"<<(sccCnt==1?0:std::max(icnt,ocnt));
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
//std::cin>>t;
while (t--) fc();
return 0;
}